import random
import requests
from get_anti_content import get_anti_content, get_proxy_no, get_access_token

cookies = {
    '_bee': 'j4sFD92EXhkNW1g6CBXTtVFhzZfFD0yO',
    '_f77': 'eff1e851-acec-4086-a75c-8103cb0a5907',
    '_a42': 'be292171-864e-45ac-a08b-68971f365e12',
    'rckk': 'j4sFD92EXhkNW1g6CBXTtVFhzZfFD0yO',
    'ru1k': 'eff1e851-acec-4086-a75c-8103cb0a5907',
    'ru2k': 'be292171-864e-45ac-a08b-68971f365e12',
    'JSESSIONID': '1C3FEBF2259448375A78D6BC542811C3',
    'api_uid': 'CiYY3mY83oxmEABoQxZcAg==',
}

headers = {
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',
    'accesstoken': 'FFI246EXOUGFUKX25C3RGY7SEEHO3GMR6FIK7PVXPSBHMFBWRWJA1200774',
    'anti-content': '0asWfqlyXjHgjgw9T0lWxATdrx3vsS2waIL87wnF-VtU7-1f781l1tF-r9MDrTlmcrMKY_1KvwfBg_UIgDHsKxetmD45cI0_VFWz4acvEOw45s4mbPETCKj4Cb2NVkRaY9YX9ikB9mlr1FS3n2Q4Y6o0Mqw-rUWwXaM8Q1eaYNLoO4s0bUk92C9ACPuTa0CF0zu9jR_xJVACgk7NdmbF4YUHR9IheAnV5cF4kuRPMDkJXBJamcFgdN4IRwLHKQG1PqJasoFXcr17Xtsd8yob_EafHMPDxyob4kbVxdxlJ42s62R4Y6Eqs-u25oF0L18nPEWAnqlpFJgE4z3o9_WVmLSb0Ye99R8dLinwuYH3Tk3jLsefMQMUi1ONvqBXrzgAP14u2sI84eKUDm0h1mQXBNJSNY83SWEAaJh-iqNLf2s1ycy4SD6bbUAtAHAO5qGF-Qv_oTjJh2uQTkAq7M314zGZRMX1hhtdWfbjZI9iEwLYerb7doTNAyOsBpxMNJteZCHXvjA0D5SCzHBfV-Qd12kI8nwTYxyMl7jhXKQIfgbr7tiO_wjzfcAg0MRnAVx3eqpyoLl3tj2yj2yT1VXpcbu3s_JZb8KTU87AgYq8mMbIvLAS9FXIBDxJ_FtMIuMgifKtfUy3xPy6leldjRtzNkYOWT1nF4ydxJqhuHnivEzozbcs2tXFghV7DTCubqWqP36T2XiTCCJHzFI-ksMOusNcHwwRVOTIiNcBZE7Yan',
    'content-type': 'application/json;charset=UTF-8',
    'origin': 'https://ktt.pinduoduo.com',
    'priority': 'u=1, i',
    'referer': 'https://ktt.pinduoduo.com/',
    'sec-ch-ua': '"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
    # 'cookie': '_bee=j4sFD92EXhkNW1g6CBXTtVFhzZfFD0yO; _f77=eff1e851-acec-4086-a75c-8103cb0a5907; _a42=be292171-864e-45ac-a08b-68971f365e12; rckk=j4sFD92EXhkNW1g6CBXTtVFhzZfFD0yO; ru1k=eff1e851-acec-4086-a75c-8103cb0a5907; ru2k=be292171-864e-45ac-a08b-68971f365e12; JSESSIONID=1C3FEBF2259448375A78D6BC542811C3; api_uid=CiYY3mY83oxmEABoQxZcAg==',
}

params = {
    'proxy_no': get_proxy_no(),
}

headers['accesstoken'] = get_access_token()

def create(json_data):
    headers['anti-content'] = get_anti_content()
    json_data['sign'] = ''.join(random.choice('0123456789ABCDEF') for _ in range(32))
    print('POST', 'https://api.pinduoduo.com/api/ktt_group/goods_library/material/create')
    response = requests.post(
        'https://api.pinduoduo.com/api/ktt_group/goods_library/material/create',
        params=params,
        cookies=cookies,
        headers=headers,
        json=json_data,
    )
    return response.json()
